#include<iostream>
#include<memory>
#include<functional>
#include<map>
#include<string>

enum CallId{
    FIRST,SECOND,THIRD,FORTH
};
std::map<CallId,std::function<void()>> handlers;

void initHandlers()
{
    //std::string first = "string";
    // std::function<void(std::string)> lambda = [&first](std::string a){
    //     std::cout << first << std::endl;
    // };
    // handlers.insert(std::make_pair(CallId::FIRST,[](std::string a){
    //     std::cout << "first" << std::endl;
    // }));
    // handlers.insert(std::make_pair(CallId::SECOND,[](std::string a){
    //     std::cout << "second" << std::endl;
    // }));
    // handlers.insert(std::make_pair(CallId::THIRD,[](std::string a){
    //     std::cout << "third" << std::endl;
    // }));
    // handlers.insert(std::make_pair(CallId::FORTH,[](std::string a){
    //     std::cout << "forth" << std::endl;
    // }));

    // 不再捕获局部变量到 lambda 中  
    handlers.emplace(CallId::FIRST, []() {  
        std::cout << "Default string for FIRST" << std::endl; // 使用常量字符串  
    });  
    handlers.emplace(CallId::SECOND, []() {  
        std::cout << "second" << std::endl;  
    });  
    handlers.emplace(CallId::THIRD, []() {  
        std::cout << "third" << std::endl;  
    });  
    handlers.emplace(CallId::FORTH, []() {  
        std::cout << "forth" << std::endl;  
    }); 
}
int main(int argc, char const *argv[])
{
    initHandlers();

    std::string str = "string";
    handlers[CallId::FIRST]();
    handlers[CallId::SECOND]();
    handlers[CallId::THIRD]();
    handlers[CallId::FORTH]();

    return 0;
}
